package cn.hengzhu.main_manager.utils;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import cn.hengzhu.main_manager.utils.config.RbMsgCommand;

public class RabbitSendMessage {

	public static void send(String caseNo,RbMsgCommand rbMsgCommand) throws IOException, TimeoutException{
		Connection connection = ConnectionUtils.getConnection();
		Channel channel = connection.createChannel();
		Map<String, Object> args = new HashMap<String, Object>();
		args.put("x-message-ttl", 40000);
		channel.queueDeclare(caseNo, true, false, false, args);
		ObjectMapper mapper = new ObjectMapper();
		String writeValueAsString = mapper.writeValueAsString(rbMsgCommand);
		channel.basicPublish("", caseNo, null, writeValueAsString.getBytes());
		channel.close();
		connection.close();
	}
}
